package com.A1908.dao.impl;

import com.A1908.entity.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

//baseDao工具类
public class DaoUtil extends BaseDao {
    public int getCount(String sql, User user) {
        Connection connection = conn();
        ResultSet resultSet = null;
        Object[] objects = {user.getId()};
        PreparedStatement preparedStatement = pstmt(connection, sql, objects);
        try {
            resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                return resultSet.getInt(1);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return -1;
    }
}
